/**
 * 
 */
package com.mc.list;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author w.weizhen
 *
 */
public class ListCopyTest
{
    
    /**
     * @param args
     */
    public static void main(String[] args)
    {
        
//        List<Integer> sourceList = new ArrayList<>();
//        sourceList.add(1);
//        sourceList.add(2);
//        sourceList.add(3);
//        
//        // 初始化目标集合，确保其容量至少与源集合相同
//        List<Integer> targetList = new ArrayList<Integer>();
//        Collections.copy(targetList, sourceList);
//        
//        sourceList.add(4);
//        
//        System.out.println(targetList); // 输出: [1, 2, 3]
        
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            list.add(i);
        }

        //list深度拷贝
        List<Integer> newList = new ArrayList<>();
//        CollectionUtils.addAll(newList, new Object[list.size()]);
//        Collections.copy(newList, list);
//        newList.set(0, 10);
        
        newList.addAll(list);  
        
        for (int i = 10; i < 20; i++) {
            list.add(i);
        }
        
        newList.add(100);
        
        System.out.println("原list值：" + list);
        System.out.println("新list值：" + newList);
        
    }
    
}
